#include "command_line_builder.h"
#include "../base/debug.h"
#include "../base/safe_format.h"
#include "const_cmd_line.h"

CommandLineBuilder::CommandLineBuilder(CommandLineMode mode) : mode_(mode)
{
}

CommandLineBuilder::~CommandLineBuilder()
{
}

CString CommandLineBuilder::GetCommandLineArgs() const
{
	CString cmd_line_args;

	switch (mode_)
	{
	case COMMANDLINE_MODE_NOARGS:
		cmd_line_args.Empty();
		break;

	//case COMMANDLINE_MODE_CORE:

	case COMMANDLINE_MODE_SERVICE:
		cmd_line_args = GetService();
		break;

	case COMMANDLINE_MODE_REGSERVER:
		cmd_line_args = GetRegServer();
		break;

	case COMMANDLINE_MODE_UNREGSERVER:
		cmd_line_args = GetUnregServer();
		break;

	case COMMANDLINE_MODE_SERVICE_REGISTER:
		cmd_line_args = GetServiceRegister();
		break;
	case COMMANDLINE_MODE_SERVICE_UNREGISTER:
		cmd_line_args = GetServiceUnregister();
		break;

	case COMMANDLINE_MODE_COMSERVER:
		cmd_line_args = GetComServer();
		break;

	case COMMANDLINE_MODE_UNKNOWN:
	default:
		ASSERT1(false);
		break;
	}

#ifdef _DEBUG
	CString full_command_line;
	SafeCStringFormat(&full_command_line, _T("pcagent.exe %s"), cmd_line_args);
	CommandLineArgs args;
	ASSERT1(SUCCEEDED(ParseCommandLine(full_command_line, &args)));
#endif

	return cmd_line_args;
}

CString CommandLineBuilder::GetSingleSwitch(const CString& switch_name) const
{
	CString cmd_line;
	cmd_line.Format(_T("/%s"), switch_name);
	return cmd_line;
}

CString CommandLineBuilder::GetRegServer() const
{
	return GetSingleSwitch(kCmdRegServer);
}

CString CommandLineBuilder::GetUnregServer() const
{
	return GetSingleSwitch(kCmdUnregServer);
}

CString CommandLineBuilder::GetComServer() const {
	return kCmdLineComServerDash;
}

CString CommandLineBuilder::GetServiceRegister() const
{
	return GetSingleSwitch(kCmdLineRegisterService);
}

CString CommandLineBuilder::GetServiceUnregister() const 
{
	return GetSingleSwitch(kCmdLineUnregisterService);
}

CString CommandLineBuilder::GetService() const
{
	return GetSingleSwitch(kCmdLineService);
}